package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.reggie.common.PageParams;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrdersDto;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders) {
        orderService.submit(orders);
        return R.success("支付成功");
    }

    @GetMapping("/page")
    public R findPage(int page, int pageSize, String number, String beginTime, String endTime) {

        IPage<OrdersDto> ordersDtoIPage = orderService.fandPage(page, pageSize, number, beginTime, endTime);
        return R.success(ordersDtoIPage);
    }

    @PutMapping
    public R updatOrdersStatus(@RequestBody Orders orders) {
        int row = orderService.updateStatus(orders);
        return R.success("修改成功");
    }

    /**
     * 获取所有的订单
     */
    @GetMapping("/userPage")
    public R selectAllOrdes(Integer page, Integer pageSize) {

         IPage ordesDtoPage= orderService.fandOrders(page,pageSize);
        return R.success(ordesDtoPage);
    }
}
